/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.VentaDetalleM;
import MsSQL.ConMsSQL;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;

/**
 *
 * @author Maryluz
 */
public class VentaDetalleC {
    
     public boolean agregarVentaDetalle(VentaDetalleM ovM) {

        Connection cnn = ConMsSQL.obtenerConexion();
        try {
            if (cnn != null) {
                String sql = "{call sp_addVentaDetalle(?,?,?,?,?)}";
                CallableStatement cs = cnn.prepareCall(sql);
                cs.setInt(1, ovM.getIdVenta());
                cs.setInt(2, ovM.getIdPrenda());
                cs.setInt(3, ovM.getIdTienda());
                cs.setInt(4, ovM.getCantidad());
                cs.setDouble(5, ovM.getImporte());
//                
//                System.out.println(ovM.getIdVenta());
//                System.out.println(ovM.getIdPrenda());
//                System.out.println(ovM.getIdTienda());
//                System.out.println(ovM.getCantidad());
//                System.out.println(ovM.getImporte());
//                
                ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                       return true;
                    }
                }
                return false;
            }
        } catch (Exception e) {
            // System.out.print(e);
          return false;
        }
        return false;
    }
     
     public boolean actualizarStock(int idTienda, int idPrenda) {

        Connection cnn = ConMsSQL.obtenerConexion();
        try {
            if (cnn != null) {
                String sql = "{call sp_updStock("+idTienda+","+idPrenda+")}";
                CallableStatement cs = cnn.prepareCall(sql);
                ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                       return true;
                    }
                }
                return false;
            }
        } catch (Exception e) {
            // System.out.print(e);
          return false;
        }
        return false;
    }
     
     public boolean actualizarStockDevoluciones(int idTienda, int idPrenda) {

        Connection cnn = ConMsSQL.obtenerConexion();
        try {
            if (cnn != null) {
                String sql = "{call sp_updStockDevoluciones("+idTienda+","+idPrenda+")}";
                CallableStatement cs = cnn.prepareCall(sql);
                ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                       return true;
                    }
                }
                return false;
            }
        } catch (Exception e) {
            // System.out.print(e);
          return false;
        }
        return false;
    }

}
